/**
* 这个类是用来作为一个小的工具类，当中定义了几个常用的方法。
*/
var Event = new Object();
Event.obvser = function(ele,evt,fun,bool){
  if(ele.addEventListener){
     ele.addEventListener(evt, fun, bool);
  } else{ ele.attachEvent("on"+evt, fun, bool); }
}
Event.pointerX = function(event) {
    return event.pageX || (event.clientX +
      (document.documentElement.scrollLeft || document.body.scrollLeft));
  }
Event.pointerY = function(event) {
    return event.pageY || (event.clientY +
      (document.documentElement.scrollTop || document.body.scrollTop));
}
Event.stop = function(event) {
    if (event.preventDefault) {
      event.preventDefault();
      event.stopPropagation();
    } else {
      event.returnValue = false;
      event.cancelBubble = true;
    }
  }
function SearchEvent()
{
    func=SearchEvent.caller;
    while(func!=null)
    {
        var arg0=func.arguments[0];
        if(arg0)
        {
            if(arg0.constructor==Event)
                return arg0;
        }
        func=func.caller;
    }
    return null;
}
var Position = new Object();

//注意body的margin必须为0

Position.getPageOffset=function(obj){
  var point=[0,0];
  var a=obj;
  while(a && a.offsetParent)
  {
   point[0]+=a.offsetLeft;
   point[1]+=a.offsetTop;
   a=a.offsetParent
  }
  return point;
}
function getQueryString(key)
{
	var url=document.URL;
	if(url.indexOf("?")>0)
	{
		var params=url.substr(url.indexOf("?")+1).split("&");
		for(var i=0;i<params.length;i++)
		{
			var index=params[i].indexOf("=");
			if(index>0)
			{
				var name=params[i].substr(0,index);
				var value=params[i].substr(index+1);
				if(name==key)
				{
					return decodeURIComponent(value);
				}
			}
		}
	}
	return "";
};
function getQueryStringByHash(key)
{
	var url=document.URL;
	if(url.indexOf("#")>0)
	{
		var params=url.substr(url.indexOf("#")+1).split("&");
		for(var i=0;i<params.length;i++)
		{
			var index=params[i].indexOf("=");
			if(index>0)
			{
				var name=params[i].substr(0,index);
				var value=params[i].substr(index+1);
				if(name==key)
				{
					return decodeURIComponent(value);
				}
			}
		}
	}
	return "";
};


//定时器
//一个定时器
function Time(init){
	this.init = init;
	this.enable = false;
	this.evtHandle = null;
	this.timeout = null;
	this.fun = function(){
		window.clearTimeout(this.timeout);
		this.enable = false;
		if(this.evtHandle){
			this.evtHandle();
		}
	}
	this.jian = function(){
		this.currTime++;
	}
	this.currTime = 0;
}
Time.prototype.setEvent = function(handle){
	this.evtHandle = handle;
	
}
Time.prototype.start = function(){
	this.enable = true;
	this.currTime = 0;
	var obj = this;
	this.timeout = window.setTimeout(function(){return obj.fun.call(obj)},this.init);
	this.interv = window.setInterval(function(){return obj.jian.call(obj)},1);
}
Time.prototype.end = function(){
	window.clearTimeout(this.timeout);
	window.clearInterval(this.interv);
	this.enable = false;
}